package cn.cxl.cxlutils;

import android.app.Application;
import android.os.Environment;

import java.io.File;

import cn.cxl.cxlutils.utils.LogcatFileManager;

/**
 * ====================================================
 * <p>
 * 作者：CXL
 * <p>
 * 创建时间：2022/5/31 13:48
 * ====================================================
 */
public class MyApplication extends Application {
    @Override
    public void onCreate() {

        super.onCreate();
        startLogcatManager();


    }
    private void startLogcatManager() {
        String folderPath = null;

        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {// save in SD card first
            folderPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "BDT-Logcat";
        } else {// If the SD card does not exist, save in the directory of application.

            folderPath = this.getFilesDir().getAbsolutePath() + File.separator + "BDT-Logcat";
        }

        LogcatFileManager.getInstance().start(folderPath);
    }
    @Override
    public void onTerminate() {
        stopLogcatManager();
        super.onTerminate();
    }
    private void stopLogcatManager() {

        LogcatFileManager.getInstance().stop();
    }
}
